package com.office.stacks.mine.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.office.stacks.mine.service.IHurtlessService;
import com.office.stacks.pubilsh.domain.Tasks;
import com.office.web.controller.file.server.FileUploadServer;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.office.common.annotation.Log;
import com.office.common.core.controller.BaseController;
import com.office.common.core.domain.AjaxResult;
import com.office.common.enums.BusinessType;
import com.office.common.utils.poi.ExcelUtil;
import com.office.common.core.page.TableDataInfo;

/**
 * 我的任务Controller
 *
 * @author 柒月
 * @date 2025-05-23
 */
@RestController
@RequestMapping("/hurtless/minestacks")
public class HurtlessController extends BaseController {

    @Autowired
    private IHurtlessService hurtlessService;

    /**
     * 查询我的任务列表
     */
    @PreAuthorize("@ss.hasPermi('hurtless:minestacks:list')")
    @GetMapping("/list")
    public TableDataInfo list(Tasks tasks) {
        startPage();
        List<Tasks> list = hurtlessService.selectTasksList(tasks);
        return getDataTable(list);
    }

    /**
     * 导出我的任务列表
     */
    @PreAuthorize("@ss.hasPermi('hurtless:minestacks:export')")
    @Log(title = "我的任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Tasks tasks) {
        List<Tasks> list = hurtlessService.selectTasksList(tasks);
        ExcelUtil<Tasks> util = new ExcelUtil<Tasks>(Tasks.class);
        util.exportExcel(response, list, "我的任务数据");
    }

    /**
     * 提交我的任务
     */
    @PreAuthorize("@ss.hasPermi('hurtless:minestacks:submit')")
    @Log(title = "提交我的任务" , businessType = BusinessType.UPDATE)
    @PutMapping("/submit/{id}/{fileId}")
    public AjaxResult getInfo(@PathVariable("id") Long id, @PathVariable("fileId") Long fileId) {
        return success(hurtlessService.submitTasksById(id,fileId));
    }

    /**
     * 确认我的任务
     */
    @PreAuthorize("@ss.hasPermi('hurtless:minestacks:determine')")
    @Log(title = "确认我的任务", businessType = BusinessType.UPDATE)
    @PutMapping("/{ids}")
    public AjaxResult determine(@PathVariable Long[] ids) {
        return toAjax(hurtlessService.determineTasks(ids));
    }

    /**
     * 修改任务表的文件id为null
     */
    @PutMapping("/file/{fileId}")
    public AjaxResult updataFileId(@PathVariable Long fileId) {
        return toAjax(hurtlessService.updataFileById(fileId));
    }

}
